package com.twu.biblioteca;

import com.twu.model.Book;
import com.twu.model.Movie;

import java.util.*;
/**
 * Created by Janu on 20/06/14.
 * Class: Data Set
 */

//Comparators for TreeSets
class myBooksComp implements Comparator<Book> {

    @Override
    public int compare(Book b1, Book b2) {
        return b1.getBookCode().compareTo(b2.getBookCode());
    }
}

class myMoviesComp implements Comparator<Movie> {

    @Override
    public int compare(Movie m1, Movie m2) {
        return m1.getMovCode().compareTo(m2.getMovCode());
    }
}
class myCustomerComp implements Comparator<Customer> {

    @Override
    public int compare(Customer c1, Customer c2) {
        return c1.getCustName().compareTo(c2.getCustName());
    }
}

public class DataSet {

    private TreeSet<Book> books;
    private TreeSet<Movie> movies;
    private TreeSet<Customer> customers;

    public DataSet(){
        this.books = new TreeSet<Book>(new myBooksComp());
        this.movies = new TreeSet<Movie>(new myMoviesComp());
        this.customers = new TreeSet<Customer>(new myCustomerComp());
    }

    private void createBookDataSet(){

        this.books.add(new Book("B01", "Head First Java", "Kathy Sierra & Bert Bates", 2011,true));
        this.books.add(new Book("B02", "Test Driven Development: by Example", "Kent Beck", 2010,true));
        this.books.add(new Book("B03", "Twilight", "Stephanie Meyer", 2013,true));
        this.books.add(new Book("B04", "Java: The Complete Reference", "Herbert Schildt", 2001,true));
        this.books.add(new Book("B05", "Refactoring: Improving the Design of Existing Code", "Martin Fowler",1999,true));

    }

    private void createMovieDataSet(){
        this.movies.add(new Movie("M01", "3 Idiots", 2010, "ABC", 9, true));
        this.movies.add(new Movie("M02", "Jodha Akbar", 2009, "PQR", 9, true));
        this.movies.add(new Movie("M03", "Dhoom 3", 2013, "XYZ", 7, true));
    }

    private void createCustomerDataSet(){
        this.customers.add(new Customer("111-2222", "bbb", "John", "john@gmail.com", "9901111066"));
        this.customers.add(new Customer("123-4567","aaa","Sam", "sam@gmail.com", "9844494088"));
    }

    public TreeSet<Book> getBookDataSet(){ this.createBookDataSet(); return this.books; }

    public TreeSet<Movie> getMoviesDataSet(){ this.createMovieDataSet(); return this.movies; }

    public TreeSet<Customer> getCustomersDataSet(){ this.createCustomerDataSet(); return this.customers; }



}
